﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Web;
using System.Web.Caching;

namespace ProjectBase.Core.Storage
{
    /// <summary>
    ///     Allows get and set data to the Cache object withe CacheDependency
    /// </summary>
    public class CacheStorage : ICacheStorage
    {
        /// <summary>
        ///     The cache implementation
        /// </summary>
        static Cache Cache
        {
            get
            {
                if (HttpContext.Current.IsNull())
                {
                    return HttpRuntime.Cache;
                }
                return HttpContext.Current.Cache;
            }
        }

        #region ICacheStorage Members

        public virtual object this[string key]
        {
            get { return Cache[key]; }
            set { Cache[key] = value; }
        }

        public virtual void Insert(string key, object value, CacheDependency dependencies)
        {
            Cache.Insert(key, value, dependencies);
        }

        public virtual void Insert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration,
            TimeSpan slidingExpiration)
        {
            Cache.Insert(key, value, dependencies, absoluteExpiration, slidingExpiration);
        }
        public virtual void Remove(string key)
        {
            Cache.Remove(key);
        }
        #endregion
    }
}